{% extends 'base_backend.html' %}
{% load static %}
{% load my_filter %}

{% block header_tail %}
    <link rel="stylesheet" href="{% static 'zhongbao/zhongbao_admin/css/style.css' %}">
    <link rel="stylesheet" href="{% static 'zhongbao/zhongbao_admin/css/iconfont.css' %}">
    <link rel="stylesheet" href="{% static 'plugins/datatables/dataTables.bootstrap.css' %}">
    <link rel="stylesheet" href="{% static 'public/ComboSelect/css/combo.select.css' %}">
    <link rel="stylesheet" href="{% static 'zhongbao/config/css/main.css' %}">
    <link rel="stylesheet" href="{% static 'laydate/theme/default/laydate.css' %}">
    <script src="{% static 'laydate/laydate.js' %}"></script>
    <script src="{% static 'plugins\jQuery\jquery-2.2.3.min.js' %}"></script>

    <script src="{% static 'plugins/vue1/vue.js' %}"></script>

    <style>
        .login-banner {
            width: 100%;
            background: url("{% static 'public/img/banner2.jpg' %}") center bottom/cover no-repeat;
        }
    </style>
{% endblock header_tail %}

{% block section_content %}
    {% if is_agent == 1 %}
        {% include 'base_agent_statistics.html' with manage_type=manage_type %}
    {% endif %}
    {% if is_agent != 1 %}
        {% include 'base_admin_statistics.html' with manage_type=manage_type %}
    {% endif %}

    <div>
        <div class="box-header with-border">
            <h3 class="box-title">{{ model_verbose_name }}</h3>
        </div>
        <!-- form start -->
        <div class="box box-primary">
            <div class="box-header with-border" style="border-color: #1b6d85">

                <!-- Date range -->
                <form role="form" id="searchForm">
                    <input class="no-display" type="text">
                    <p style="clear: both"></p>
                    <div style="width: 95%; float: left;">
                        <div style="float: left;" class="input-group select-config-div">
                            <label for="id" class="control-label">任务ID：</label>
                            <p>
                                <input id="taskId" name="id" type="text" class="config-input">
                            </p>

                        </div>
                        {% for field in form %}
                            <div class="input-group select-config-div" style="float: left; ">
                                <label for="" class="control-label">{{ field.label }}：</label>
                                <p>{{ field }}</p>
                            </div>
                        {% endfor %}
                        <div style="float: left;" class="input-group select-config-div">
                            <label for="id" class="control-label">任务状态：</label>
                            <select name="status" id="taskStatus" class="config-input">
                                {% for filter in filters %}
                                    {% if filter.code == status %}
                                        <option selected="selected"
                                                value="{{ filter.code }}">{{ filter.description }}</option>
                                    {% else %}
                                        <option value="{{ filter.code }}">{{ filter.description }}</option>
                                    {% endif %}
                                {% endfor %}
                            </select>
                        </div>
                        <div style="float: left;" class="input-group select-config-div">
                            <label for="id" class="control-label">任务不合格次数：</label>
                            <p>
                                <input id="disqualify_num" name="disqualify_num" type="number" class="config-input">
                            </p>
                        </div>
                        <div style="float: left;" class="input-group select-config-div">
                            <label for="id" class="control-label">是否提交质检：</label>
                            <select name="is_submit_quality" id="is_submit_quality" class="config-input">
                                <option selected="selected" value="">全部</option>
                                <option value="True">是</option>
                                <option value="False">否</option>
                            </select>
                        </div>
                        <div style="float: left;" class="input-group select-config-div">
                            <label for="id" class="control-label">任务优先级：</label>
                            <select name="priority" id="priority" class="config-input">
                                <option selected="selected" value="">全部</option>
                                <option value="特急">特急</option>
                                <option value="高级">高级</option>
                                <option value="中级">中级</option>
                                <option value="低级">低级</option>
                            </select>
                        </div>
                        <div style="float: left;" class="input-group select-config-div">
                            <label for="id" class="control-label">不合格原因：</label>
                            <select name="disqualify_reason_new" id="disqualify_reason_new" class="config-input">
                                <option selected="selected" value="">全部</option>
                                <option value="备案号未填写">备案号未填写</option>
                                <option value="代码错误">代码错误</option>
                                <option value="配置分组错误">配置分组错误</option>
                                <option value="配置编码">配置编码</option>
                                <option value="采集时限错误">采集时限错误</option>
                                <option value="info_flag错误">info_flag错误</option>
                                <option value="国家错误">国家错误</option>
                                <option value="语言错误">语言错误</option>
                                <option value="域名错误">域名错误</option>
                                <option value="url错误">url错误</option>
                                <option value="title错误">title错误</option>
                                <option value="ctime错误">ctime错误</option>
                                <option value="source错误">source错误</option>
                                <option value="source_id错误">source_id错误</option>
                                <option value="retweeted_source错误">retweeted_source错误</option>
                                <option value="retweeted_status_url错误">retweeted_status_url错误</option>
                                <option value="channel错误">channel错误</option>
                                <option value="pic_urls错误">pic_urls错误</option>
                                <option value="sitename错误">sitename错误</option>
                                <option value="visitCount错误">visitCount错误</option>
                                <option value="replyCount错误">replyCount错误</option>
                                <option value="content错误">content错误</option>
                                <option value="content_xml错误">content_xml错误</option>
                                <option value="audio_urls错误">audio_urls错误</option>
                                <option value="video_urls错误">video_urls错误</option>
                                <option value="face_img错误">face_img错误</option>
                                <option value="is_junk错误">is_junk错误</option>
                                <option value="网站名称内外不一致">网站名称内外不一致</option>
                                <option value="其他">其他</option>
                            </select>
                        </div>
                        <div style="float: left;" class="input-group select-config-div">
                            <label for="id" class="control-label">每页显示：</label>
                            <select name="limit" id="showNumSelect" class="config-input">
                                {% for i in limits %}
                                    {% if i == limit %}
                                        <option selected="selected" value="{{ i }}">{{ i }}条</option>
                                    {% else %}
                                        <option value="{{ i }}">{{ i }}条</option>
                                    {% endif %}
                                {% endfor %}
                            </select>
                        </div>
                        <div style="float: left;" class="input-group select-config-div">
                            <label for="" class="control-label">代理机构：</label>
                            <select name="agency_id" id="" class="config-input">
                                <option value="">全部</option>
                                {% for agency in agency_list %}
                                    <option value="{{ agency.id }}">{{ agency.agent_name }}</option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="input-group" style="width:5%;float: left;">
                            <input type="text" class="no-display">
                            <span id="searchBtn" onclick="searchTasks()"
                                  class="form-control pull-left btn btn-sm btn-primary"
                                  style="margin-top:20px;width: 50px">检索
                        </span>
                        </div>
                        <div class="input-group" style="width:5%;float: left;">
                     <span id="searchBtn" onclick="TasksDownload()"
                           class="form-control pull-left btn btn-sm btn-primary"
                           style="margin-top:20px;width: 50px">下载
                        </span>
                        </div>
                        <p style="clear: both"></p>
                        <div class="form-group">
                        </div>
                    </div>

                </form>
            </div>
            <!--
                <div class="box-header with-border" style="border-color: #1b6d85">
                </div>
                <div id="ItemsTree" style="position:absolute;left:200px;top:90px; display:none;width:250px;height:300px;border:dashed 1px #000000; background-color:#F7F7F7; overflow:auto"></div>
            -->
            <!-- 展示搜索出来的任务 -->
            <div id="main">
                <div id="showMessage" v-show="message"> [[ message ]]</div>
                <div class="box-body" v-show="showMain">
                    <form id="model_form" role="form"
                          method="post">{% csrf_token %}
                        <div class="group">
                            <!--
                            {/% for action in actions %}
                                {/% if action.status == 1 %}
                                    <button style="margin-right:20px;" type="button" class="btn btn-primary btn-xs" disabled="true" status="{/{ action.status }}" onclick="allocateTasks(this)">{/{ action.name }}</button>
                                {/% else %}
                                    <button style="margin-right:20px;" type="button" class="btn btn-primary btn-xs" status="{/{ action.status }}" onclick="allocateTasks(this)">{/{ action.name }}</button>
                                {/% endif %}
                            {/% endfor %}
                            -->
                            {% if status == None %}
                                <a style="margin-right:20px;" type="button" class="btn btn-primary btn-xs">当前窗口为"
                                    {% if manage_type == 'project' %}
                                        项目管理 > 项目查询
                                    {% else %}
                                        任务管理 > 任务查询
                                    {% endif %}
                                    "窗口，不支持批量操作</a>
                            {% elif status == 1 %}
                                <a style="margin-right:20px;" type="button" class="btn btn-primary btn-xs"
                                   onclick="_allocate()">分配（批量）</a>
                                {% if user.is_superuser %}
                                    <a style="margin-right:20px;" type="button" class="btn btn-primary btn-xs"
                                       onclick="_retrieve()">回收（批量）</a>
                                    <a style="margin-right:20px;" type="button" class="btn btn-primary btn-xs">同一项目id的任务才可以批量分配</a>
                                {% endif %}
                            {% elif status == 2 %}
                                {% if user.is_superuser %}
                                    <a style="margin-right:20px;" type="button" class="btn btn-primary btn-xs"
                                       onclick="_retrieve()">回收（批量）</a>
                                {% endif %}
                                {% if is_agent %}
                                    <a style="margin-right:20px;" type="button" class="btn btn-primary btn-xs"
                                       onclick="_Assignment()">重新分配（批量）</a>
                                {% endif %}
                            {% elif status == 3 %}
                                {% if user.is_superuser %}
                                    <a style="margin-right:20px;" type="button" class="btn btn-primary btn-xs"
                                       onclick="_pass()">判为合格（批量）</a>
                                    <a style="margin-right:20px;" type="button" class="btn btn-primary btn-xs"
                                       onclick="_reject()">判为不合格（批量）</a>
                                {% endif %}
                                {% if is_agent and not user.is_superuser %}
                                    <a style="margin-right:20px;" type="button" class="btn btn-primary btn-xs">当前窗口为"
                                        项目管理 > 项目查询
                                        任务管理 > 任务查询
                                        "窗口，不支持批量操作</a>
                                {% endif %}
                            {% elif status == 4 %}
                                {% if user.is_superuser %}
                                    <a style="margin-right:20px;" type="button" class="btn btn-primary btn-xs"
                                       onclick="_revoke()">改判为不合格（批量）</a>
                                {% endif %}
                                {% if is_agent and not user.is_superuser %}
                                    <a style="margin-right:20px;" type="button" class="btn btn-primary btn-xs">当前窗口为"
                                        项目管理 > 项目查询
                                        任务管理 > 任务查询
                                        "窗口，不支持批量操作</a>
                                {% endif %}
                            {% elif status == 5 %}
                                {% if user.is_superuser %}
                                    <a style="margin-right:20px;" type="button" class="btn btn-primary btn-xs"
                                       onclick="_retrieve()">回收（批量）</a>
                                    <a style="margin-right:20px;" type="button" class="btn btn-primary btn-xs"
                                       onclick="_check()">改判为合格（批量）</a>
                                {% endif %}
                                {% if is_agent and not user.is_superuser %}
                                    <a style="margin-right:20px;" type="button" class="btn btn-primary btn-xs">当前窗口为"
                                        项目管理 > 项目查询
                                        任务管理 > 任务查询
                                        "窗口，不支持批量操作</a>
                                {% endif %}
                            {% endif %}
                            <span>共<b>[[ total ]]</b>个 </span>
                            {% if request.user.is_agent %}
                                <span>查询共[[ total ]]笔，你可以全选或勾选任务,建议20及以上笔任务提交质检</span>
                                <span class="btn btn-info btn-xs" onclick="submit_inspection()">提交质检</span>
                            {% endif %}
                            <table id="task_each_table" border="1"
                                   class="table table-bordered table-hover table-striped">
                                <thead>
                                <tr>
                                    <th class="action-checkbox">
                                        <input type="checkbox" name="th_checkbox" onclick="checkAll(this)">
                                    </th>
                                    <th v-for="head in tableData.headers">
                                        <span style="float: left">
                                            [[ head.name ]]
                                        </span>
                                        {% if field.rank %}
                                            <a href="?[[ head.rank ]]=[[ head.rank_tag ]][[ page_args ]]"
                                               style="float: right">
                                                {% if field.rank_tag == 0 %}
                                                    <i class="fa fa-fw fa-sort"></i>
                                                {% elif field.rank_tag == 1 %}
                                                    <i class="fa fa-fw fa-sort-numeric-asc"></i>
                                                {% elif field.rank_tag == -1 %}
                                                    <i class="fa fa-fw fa-sort-numeric-desc"></i>
                                                {% endif %}
                                            </a>
                                        {% endif %}
                                    </th>
                                    <th>
                                        <span style="float: left">
                                            操作
                                        </span>
                                    </th>
                                </tr>
                                </thead>
                                <tbody>
                                <template v-for="task in tableData.tasks">
                                    <!--<tr v-if="task.allocation_flag">-->
                                    <tr>
                                        <td class="action-checkbox">
                                            <input type="checkbox" name="td_checkbox" id="[[task.agency]]"
                                                   value="[[ task.id ]]" status_id="[[ parseStatus(task.status) ]]"

                                                   onclick="checkOne(this)">
                                        </td>
                                        <template v-for="head in tableData.headers">
                                            <template
                                                    v-if="head.key == 'submit_flag' || head.key == 'allocation_flag'|| head.key == 'deadline_flag' || head.key == 'receive_flag' || head.key == 'finish_flag' || head.key == 'qualified_passed_flag' || head.key == 'ctime' || head.key == 'unqualified_flag' || head.key == 'status'">
                                                <td v-if="head.key == 'status'">[[ parseStatus(task[head.key]) ]]</td>
                                                <td v-else>[[ parseTime(task[head.key]) ]]</td>
                                            </template>
                                            <template v-else>
                                                <td v-if="head.key == 'site_url'"><a href="[[ task[head.key] ]]"
                                                                                     target="_Blank"
                                                                                     title="[[ task[head.key] ]]">[[
                                                    truncatechars(task[head.key], 30) ]]</a></td>
                                                <td v-else title="[[ task[head.key] ]]">[[ truncatechars(task[head.key],
                                                    10) ]]
                                                    <span v-if="head.key == 'disqualify_reason_new' && [[ task[head.key] ]] != ''"
                                                          id="copy_button"
                                                          style="background: #d2c3c3; font-size: 2px; cursor: pointer"
                                                          onclick="copy_text('[[ task[head.key] ]]')">复制</span>
                                                </td>
                                            </template>
                                        </template>
                                        <td class="btn-group">
                                            <button v-if="task.status == 1" type="button" value="[[ task.id ]]"
                                                    class="btn btn-info btn-xs"
                                                    onclick="allocateOneTask([[task.id]], [[task.agency]])">分配
                                            </button>
                                            <button v-if="task.status == 2 || task.status == 5" type="button"
                                                    value="[[ task.id ]]" class="btn btn-info btn-xs"
                                                    onclick="Assignment([[task.id]],[[task.agency]])">重新分派
                                            </button>
                                            <button v-if="task.status == 8" type="button" value="[[ task.id ]]"
                                                    class="btn btn-info btn-xs" onclick="recoveryOne([[task.id]])">回收
                                            </button>
                                            <button v-if="task.status == 8" type="button" value="[[ task.id ]]"
                                                    class="btn btn-info btn-xs" onclick="disposalOne([[task.id]])">驳回
                                            </button>
                                            {% if user.is_superuser %}
                                                <a href="{% url 'task:operating_record' %}?id=[[task.id]]"
                                                   class="btn btn-info btn-xs">操作记录</a>
                                                <button v-if="task.status == 1 || task.status == 2 || task.status == 5"
                                                        type="button" value="[[ task.id ]]" class="btn btn-info btn-xs"
                                                        onclick="retrieveOneTask([[task.id]])">回收
                                                </button>
                                                <button v-if="task.status == 3" type="button" value="[[ task.id ]]"
                                                        class="btn btn-info btn-xs" onclick="passOneTask([[task.id]])">
                                                    合格
                                                </button>
                                                <!--<button v-if="task.status == 3" type="button" value="[[ task.id ]]" class="btn btn-info btn-xs" onclick="rejectOneTask([[task.id]])">不合格</button>-->
                                                <!--<button v-if="task.status == 4" type="button" value="[[ task.id ]]" class="btn btn-info btn-xs" onclick="revokeOneTask([[task.id]])">不合格</button>-->
                                                <button v-if="task.status == 3" type="button" value="[[ task.id ]]"
                                                        class="btn btn-info btn-xs" onclick="operation([[task.id]])">不合格
                                                </button>
                                                <button v-if="task.status == 4" type="button" value="[[ task.id ]]"
                                                        class="btn btn-info btn-xs" onclick="operation([[task.id]])">不合格
                                                </button>
                                                <button v-if="task.status == 5" type="button" value="[[ task.id ]]"
                                                        class="btn btn-info btn-xs" onclick="checkOneTask([[task.id]])">
                                                    合格
                                                </button>
                                            {% endif %}
                                            <button type="button" value="[[ task.id ]]" class="btn btn-info btn-xs"
                                                    onclick="detailOneTask([[task.id]])">详情
                                            </button>
                                        </td>
                                    </tr>
                                </template>
                                </tbody>
                            </table>
                            <input id="copy_text_input" type="text" value=""
                                   style="position: absolute; top: 0; left: 0; opacity: 0; z-index: -10">
                            <p class="" id="paginator">
                                <a class="btn btn-default btn-xs" v-if="paginator.current > 1"
                                   onclick="toPage('first',paginator.limit)">首页</a>
                                <a class="btn btn-default btn-xs" v-else disabled="true">首页</a>
                                <a class="btn btn-default btn-xs" v-if="paginator.current > 1"
                                   onclick="toPage('prev',paginator.limit)">上一页</a>
                                Page [[ paginator.current ]] of [[ paginator.last ]]
                                <span v-show="total">共[[ total ]]个</span>
                                <a class="btn btn-default btn-xs" v-if="paginator.current < paginator.last"
                                   onclick="toPage('next',paginator.limit)">下一页</a>
                                <a class="btn btn-default btn-xs" v-if="paginator.current < paginator.last"
                                   onclick="toPage('last',paginator.limit)">尾页</a>
                                <a class="btn btn-default btn-xs" v-else disabled="true">尾页</a>
                                <input type="text" id="page-judge" style="width: 30px;height:20px; margin-left: 20px"
                                       onkeyup="toPage('judge', paginator.limit)">
                                <a class="btn btn-default btn-xs" onclick="toPage('judge', paginator.limit)">跳页</a>
                            </p>
                        </div>
                        <!-- /.box-footer -->
                        <div class="box-footer">
                            <button class="btn btn-primary no-display" id="submit_button">确认</button>
                            <button type="button" class="btn btn-primary" id="save_submit" name="_save"
                                    style="display: none">sure
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <!--用户列表，任务分配-->
    <div class="modal fade" id="userList" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="overflow: hidden; ">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #307095;font-weight: bold;">
                    <label>请选择要分配给谁：</label>
                </div>
                <div class="modal-body" style="overflow-y: scroll; max-height: 500px;">
                    <table id="user_each_table" border="1" class="table table-bordered table-hover table-striped">
                        <thead>
                        <tr>
                            <th class="action-checkbox">
                            </th>
                            <th>
                                    <span style="float: left">
                                        用户名
                                    </span>
                            </th>
                            <th>
                                    <span style="float: left">
                                        姓名
                                    </span>
                            </th>
                        </tr>
                        </thead>
                        <tbody id='aaa'>
                        </tbody>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" id="confirm_close" class="btn btn-default"
                            data-dismiss="modal" onclick="confirmClose()">确认
                    </button>
                    <button type="button" id="cancel_close" class="btn btn-default"
                            data-dismiss="modal" onclick="cancelClose()">取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!--用户列表，任务重新分配-->
    <div class="modal fade" id="userListAssignment" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="overflow: hidden; ">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #307095;font-weight: bold;">
                    <label>请选择要分配给谁：</label>
                </div>
                <div class="modal-body" style="overflow-y: scroll; max-height: 500px;">
                    <table id="user_each_table" border="1" class="table table-bordered table-hover table-striped">
                        <thead>
                        <tr>
                            <th class="action-checkbox">

                            </th>
                            <th>
                                    <span style="float: left">
                                        用户名
                                    </span>
                            </th>
                            <th>
                                    <span style="float: left">
                                        姓名
                                    </span>
                            </th>
                        </tr>
                        </thead>
                        <tbody id='bbb'>
                        </tbody>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" id="confirm_close" class="btn btn-default"
                            data-dismiss="modal" onclick="confirmCloseAssignment()">确认
                    </button>
                    <button type="button" id="cancel_close" class="btn btn-default"
                            data-dismiss="modal" onclick="cancelCloseAssignment()">取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!--弹出提示消息-->
    <div class="modal fade" id="taskMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    请至少选择一条任务！
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">确认
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--弹出操作提示消息-->
    <div class="modal fade" id="operationMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #307095;font-weight: bold;">
                    <label>请选择反馈原因，无需反馈则直接点击领取</label>
                </div>

                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">

                    <input style="width:400px;height:100px;" type="text" id="fankui" name="fankuiyy"/>

                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="confirmCloses()"
                            data-dismiss="modal">确认
                    </button>

                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--start 任务提交质检确认-->
    <div class="modal fade" id="submit_inspection_verify" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header" style="background-color: #307095;font-weight: bold;">
                    <label>任务提交质检确认</label>
                </div>
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    全部已合格任务{{ counts.4 }}笔，已选
                    <input id="sv_count" type="text" value="0"
                           style="background: none; border: none; outline: none; width: 35px">
                    <input type="hidden" id="sv_ids">
                    笔任务，是否确认提交质检？
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        取消提交
                    </button>
                    <button type="button" class="btn btn-default" onclick="_submit_inspection()"
                            data-dismiss="modal">确定提交
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--end 任务提交质检确认-->
    <!--弹出没有选择用户的提示消息-->
    <div class="modal fade" id="userMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    请至少选择一个用户！
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">确认
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--弹出没有选择用户的提示消息-->
    <div class="modal fade" id="retrieveMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要回收吗?
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="retrieve()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--弹出没有选择用户的提示消息-->
    <div class="modal fade" id="passMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要判定为合格状态吗？
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="pass()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--弹出没有选择用户的提示消息-->
    <div class="modal fade" id="rejectMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要判定为不合格状态吗?
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="reject()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--弹出没有选择用户的提示消息-->
    <div class="modal fade" id="revokeMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要修改为不合格状态吗?
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="revoke()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>
    <!--弹出没有选择用户的提示消息-->
    <div class="modal fade" id="checkMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要修改为已合格状态吗?
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="check()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!--弹出没有选择用户的提示消息-->
    <div class="modal fade" id="recoveryMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要回收通过吗?
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="recovery()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!--弹出没有选择用户的提示消息-->
    <div class="modal fade" id="disposalMessage" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel" style="top:40%">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div id="msgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                    确定要驳回吗?
                </div>
                <div class="modal-footer" style="text-align:center;">
                    <button type="button" class="btn btn-default" onclick="disposal()"
                            data-dismiss="modal">确认
                    </button>
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal">取消
                    </button>
                </div>
            </div>
        </div>
    </div>


    <input id="taskIds" value="" style="display:none;"></input>

    <script>
        function __reject(tids) {
            $.ajaxSetup({
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    tids: tids
                }
            });
            $.post(
                "{% url 'task:reject' %}",
                function (response) {
                    var msg = response.message;
                    if (msg) {
                        alert(msg);
                    }
                    toPage("current");
                    clearCheckAll();
                }
            )
        }

        function rejectOneTask(tids) {
            if (tids) {
                tids = tids + "";
                $("#taskIds").val(tids);
                $("#rejectMessage").modal();
            } else {
                return false
            }
        }

        function operation(tids) {
            if (tids) {
                tids = tids + "";
                $("#taskIds").val(tids);
                $("#operationMessage").modal();
            } else {
                return false
            }
        }

        function _reject(tids) {
            if (!tids) {
                var _tids = [];
                $("input[name='td_checkbox']:checked").each(
                    function () {
                        _tids.push($(this).val())
                    }
                );
                tids = _tids.join();
            }
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false
            } else {
                $("#taskIds").val(tids);
                $("#rejectMessage").modal()
            }
        }

        function reject(tids) {
            if (!tids) {
                tids = $("#taskIds").val();
            }
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false
            } else {
                __reject(tids)
            }
            $("#taskIds").val("")
        }

        function __pass(tids) {
            $.ajaxSetup({
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    tids: tids
                }
            });
            $.post(
                "{% url 'task:pass' %}",
                function (response) {
                    var msg = response.message;
                    if (msg) {
                        alert(msg);
                    }
                    toPage("current");
                    clearCheckAll();
                }
            )
        }

        function passOneTask(tids) {
            if (tids) {
                tids = tids + "";
                $("#taskIds").val(tids);
                $("#passMessage").modal();
            } else {
                return false
            }
        }

        function _pass(tids) {
            if (!tids) {
                var _tids = [];
                $("input[name='td_checkbox']:checked").each(
                    function () {
                        _tids.push($(this).val())
                    }
                );
                tids = _tids.join();
            }
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false
            } else {
                $("#taskIds").val(tids);
                $("#passMessage").modal()
            }
        }

        function pass(tids) {
            if (!tids) {
                tids = $("#taskIds").val()
            }
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false
            } else {
                __pass(tids)
            }
            $("#taskIds").val("");
        }

        function __retrieve(tids) {
            $.ajaxSetup({
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    tids: tids
                }
            });
            $.post(
                "{% url 'task:retrieve' %}",
                function (response) {
                    var msg = response.message;
                    if (msg) {
                        alert(msg);
                    }
                    toPage("current");
                    clearCheckAll();
                }
            )
        }

        function retrieveOneTask(tids) {
            if (tids) {
                tids = tids + "";
                $("#taskIds").val(tids);
                $("#retrieveMessage").modal();
            } else {
                return false
            }
        }

        function _retrieve(tids) {
            if (!tids) {
                var _tids = [];
                $("input[name='td_checkbox']:checked").each(
                    function () {
                        _tids.push($(this).val())
                    }
                );
                tids = _tids.join();
            }
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false
            } else {
                $("#taskIds").val(tids);
                $("#retrieveMessage").modal()
            }
        }

        function retrieve(tids) {
            if (!tids) {
                tids = $("#taskIds").val();
            }
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false
            } else {
                __retrieve(tids)
            }
            $("#taskIds").val("")
        }

        function __revoke(tids) {
            $.ajaxSetup({
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    tids: tids
                }
            });
            $.post(
                "{% url 'task:revoke' %}",
                function (response) {
                    var msg = response.message;
                    if (msg) {
                        alert(msg);
                    }
                    toPage("current");
                    clearCheckAll();
                }
            )
        }

        function revokeOneTask(tids) {
            if (tids) {
                tids = tids + "";
                $("#taskIds").val(tids);
                $("#revokeMessage").modal();
            } else {
                return false
            }
        }

        function _revoke(tids) {
            if (!tids) {
                var _tids = [];
                $("input[name='td_checkbox']:checked").each(
                    function () {
                        _tids.push($(this).val())
                    }
                );
                tids = _tids.join();
            }
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false
            } else {
                $("#taskIds").val(tids);
                $("#revokeMessage").modal()
            }
        }

        function revoke(tids) {
            if (!tids) {
                tids = $("#taskIds").val()
            }
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false
            } else {
                __revoke(tids)
            }
            $("#taskIds").val("")
        }

        function __check(tids) {
            $.ajaxSetup({
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    tids: tids
                }
            });
            $.post(
                "{% url 'task:check' %}",
                function (response) {
                    var msg = response.message;
                    if (msg) {
                        alert(msg);
                    }
                    toPage("current");
                    clearCheckAll();
                }
            )
        }

        function checkOneTask(tids) {
            if (tids) {
                tids = tids + "";
                $("#taskIds").val(tids);
                $("#checkMessage").modal();
            } else {
                return false
            }
        }

        function _check(tids) {
            if (!tids) {
                var _tids = [];
                $("input[name='td_checkbox']:checked").each(
                    function () {
                        _tids.push($(this).val())
                    }
                );
                tids = _tids.join();
            }
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false
            } else {
                $("#taskIds").val(tids);
                $("#checkMessage").modal()
            }
        }

        function check(tids) {
            if (!tids) {
                tids = $("#taskIds").val();
            }
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false
            } else {
                __check(tids)
            }
            $("#taskIds").val("")
        }

        function _allocate(tids, agency_id) {
            if (!tids) {
                var _tids = [];
                var _agency_id = [];
                $("input[name='td_checkbox']:checked").each(
                    function () {
                        _tids.push($(this).val())
                        _agency_id.push($(this).attr('id'))
                    }
                );
                let s = _agency_id[0];
                for (let i = 1; i < _agency_id.length; i++) {
                    if (s != _agency_id[i]) {
                        alert('已选任务不属于同一代理，无法分配!')
                        return false
                    }
                }
                if (!agency_id) {
                    agency_id = s
                }
                tids = _tids.join();
            }
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false
            } else {
                $("#taskIds").val(tids);
                showUsers(tids, agency_id);
            }
        }

        function allocate(tids, uids) {
            if (!tids) {
                tids = $("#taskIds").val();
            }
            if (!uids) {
                var _uids = [];
                $("input[name='utd_checkbox']:checked").each(
                    function () {
                        _uids.push($(this).val())
                    }
                );
                uids = _uids.join();
            }
            if (uids.length === 0) {
                return false
            }
            if (tids.length === 0) {
                console.log(tids, uids);
                $("#taskMessage").modal();
                return false
            } else {
                $.ajaxSetup({
                    data: {
                        csrfmiddlewaretoken: '{{ csrf_token }}',
                        tids: tids,
                        uids: uids
                    }
                });
                $.post(
                    "{% url 'task:allocate' %}",
                    function (response) {
                        var msg = response.message;
                        console.log(msg);
                        if (msg) {
                            alert(msg);
                        }
                        mainVue.message = response.message;
                        toPage('current');
                        clearCheckAll();
                    }
                )
            }
            $("#taskIds").val("");
        }

        function allocateOneTask(tids, agency_id) {
            _allocate(tids, agency_id);


        }

        function detailOneTask(tid) {
            var url = "{% url 'task:detail' %}" + "?id=" + tid + "&type=task" + "&user=admin";
            window.location.href = url;
        }

        function confirmClose() {

            var tids = $("#taskIds").val();
            var userIds = [];
            $("input[name='utd_checkbox']:checked").each(
                function () {
                    userIds.push($(this).val());
                }
            );
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false;
            }
            uids = userIds.join();
            if (uids.length === 0) {
                $("#userMessage").modal();
                return false
            }
            allocate(tids, uids);
            $("#aaa").html('');
            _clearChecked();
        }

        function cancelClose() {
            $("#aaa").html('');
            _clearChecked();
        }

        function _clearChecked() {
            if ($("input[name='uth_checkbox']").is(":checked")) {
                $("input[name='uth_checkbox']").prop("checked", false)
            }
            $("input[name='utd_checkbox']:checked").each(
                function () {
                    $(this).prop("checked", false);
                }
            );
        }

        function showUsers(tids, agency_id) {
            var aaa = $("#aaa");
            aaa.html('');
            {% for user in configUsers %}
                if ({{ user.user.agency_id }} == agency_id ){
                aaa.append("<tr>\n" +
                    "                                    <td class=\"action-checkbox\">\n" +
                    "                                        <input type=\"radio\" name=\"utd_checkbox\" value=\"{{ user.user.id }}\" onclick=\"_checkOne(this)\">\n" +
                    "                                    </td>\n" +
                    "                                    <td>{{ user.user.username }}</td>\n" +
                    "                                    <td>{{ user.user.real_name }}</td>\n" +
                    "                                </tr>");
            }

            {% endfor %}
            if (aaa.html() === '') {
                alert('未获到该组所属用户！')
            } else {
                var userBox = $("#userList");
                userBox.modal();
            }

        }

        function checkAll(obj) {
            if ($(obj).is(":checked")) {
                $("input[name='td_checkbox']").prop("checked", true)
            } else {
                $("input[name='td_checkbox']").prop("checked", false)
            }

        }

        function clearCheckAll() {
            $("input[name='th_checkbox']").prop("checked", false)
        }

        function checkOne(obj) {
            if ($("input[name='th_checkbox']").is(":checked")) {
                $("input[name='th_checkbox']").prop("checked", false)
            } else {
                var unChecked = 0;
                $("input[name='td_checkbox']").each(
                    function () {
                        if ($(this).is(":checked")) {

                        } else {
                            unChecked += 1
                        }
                    }
                );
                if (unChecked === 0) {
                    $("input[name='th_checkbox']").prop("checked", true)
                }
            }
        }

        function _checkAll(obj) {
            if ($(obj).is(":checked")) {
                $("input[name='utd_checkbox']").prop("checked", true)
            } else {
                $("input[name='utd_checkbox']").prop("checked", false)
            }

        }

        function _checkOne(obj) {
            if ($("input[name='uth_checkbox']").is(":checked")) {
                $("input[name='uth_checkbox']").prop("checked", false)
            } else {
                var unChecked = 0;
                $("input[name='utd_checkbox']").each(
                    function () {
                        if ($(this).is(":checked")) {

                        } else {
                            unChecked += 1
                        }
                    }
                );
                if (unChecked === 0) {
                    $("input[name='uth_checkbox']").prop("checked", true)
                }
            }
        }

        Vue.config.delimiters = ["[[", "]]"];


        function confirmCloses() {
            var tids = $("#taskIds").val();
            var fankui = $("#fankui").val();
            var uid = {{ user_id|safe }};
            var cvalue = fankui + "#" + uid
            // alert(cvalue);
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false;
            }
            if (cvalue === '') {
                $("#taskMessage").modal();
                return false
            } else {
                n_reject(tids, cvalue)
            }

        }


        function n_reject(tids, cvalue) {
            var tid = tids;
            var cvalue = cvalue;
            $.ajaxSetup({
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    tids: tids,
                    cvalue: cvalue,
                }
            });
            $.post(
                "{% url 'task:reject' %}",
                function (response) {
                    var msg = response.message;
                    if (msg) {
                        alert(msg);
                    }
                    toPage("current");
                    clearCheckAll();
                }
            )
        }


        function toPage(page) {
            if (mainVue.paginator) {
                if (page == 'current') {
                    page = mainVue.paginator.current
                }
                if (page == 'next') {
                    page = mainVue.paginator.current + 1
                }
                if (page == 'prev') {
                    page = mainVue.paginator.current - 1
                }
                if (page == 'first') {
                    page = 1
                }
                if (page == 'last') {
                    page = mainVue.paginator.last
                }
                if (page == 'judge') {
                    page = $("#page-judge").val();
                }
                if (page < 1) {
                    page = 1;
                }
                if (page > mainVue.paginator.last) {
                    page = mainVue.paginator.last;
                }
                if (page < mainVue.paginator.first) {
                    page = mainVue.paginator.first;
                }
            } else {
                page = 1;
            }
            mainVue.page = page;
            render(mainVue);
        }

        var is_agent = '{{ is_agent }}'
        var project_id = '{{ project_id }}'

        function render(obj) {
            if (is_agent === '1') {
                var searchForm = obj.searchForm + '&page=' + obj.page + '&is_agent=' + is_agent + '&project_id=' + project_id;
            } else {
                var searchForm = obj.searchForm + '&page=' + obj.page;
            }
            $.get(
                "{% url 'task:filter_tasks_admin' %}",
                searchForm,
                function (response) {
                    if (response) {
                        obj.showMain = true;
                        obj.tableData = response.tableData;
                        obj.paginator = response.paginator;
                        obj.message = response.message;
                        obj.total = response.total;
                        obj.incomes = response.incomes;
                        console.log(obj.tableData);
                    } else {
                        obj.showMain = false;
                    }
                }
            )
        }

        var mainVue = new Vue({
            el: "#main",
            data: {
                page: 1,
                status: 1,
                limit: {{ limit }},
                searchForm: "",
                checkedAll: false,
                showMain: false,
                tableData: {},
                paginator: {},
                total: "",
                incomes: "",
                message: ""
            },
            methods: {
                parseTime: function (timeStamp) {
                    if (!timeStamp) {
                        return ""
                    }
                    var newDate = new Date();
                    newDate.setTime(timeStamp * 1000);
                    return newDate.toLocaleDateString()
                },
                truncatechars: function (str, end) {
                    if (typeof (str) != "string") {
                        return str
                    }
                    if (end <= str.length) {
                        return str.slice(0, end) + '...'
                    } else {
                        return str
                    }
                },
                parseStatus: function (status) {
                    var statuses = {
                        1: {
                            name: "待分配"
                        },
                        2: {
                            name: "处理中"
                        },
                        3: {
                            name: "待审核"
                        },
                        4: {
                            name: "已合格"
                        },
                        5: {
                            name: "不合格"
                        },
                        6: {
                            name: "已结算"
                        },
                        0: {
                            name: "已回收"
                        },
                        8: {
                            name: "回收申请"
                        },
                        9: {
                            name: "回收通过"
                        },
                        10: {
                            name: "回收驳回"
                        },
                        11: {
                            name: "已通过"
                        }
                    };
                    return statuses[status]["name"]
                },

                //searchTasks: searchTasks,
                getTasks: function () {
                    if (is_agent === '1') {
                        var searchForm = 'page=' + this.page + '&limit=' + this.limit + '&status=' + this.status + '&is_agent=' + is_agent + '&project_id=' + project_id;
                    } else {
                        var searchForm = 'page=' + this.page + '&limit=' + this.limit + '&status=' + this.status;
                    }
                    $.get(
                        "{% url 'task:filter_tasks_admin' %}",
                        searchForm,
                        function (response) {
                            if (response) {
                                this.showMain = true;
                                this.tableData = response.tableData;
                                this.paginator = response.paginator;
                                this.message = response.message;
                                this.total = response.total;
                                this.incomes = response.incomes;
                                console.log(this.paginator);
                            } else {
                                this.showMain = false;
                            }
                        }
                    )
                }
            },
            watch: {
                {#                page: function(){#}
                {#                    render(this);#}
                {#                }#}
            }
        });

        function searchTasks() {
            var uid = {{ uid|safe }};
            if (is_agent === '1') {
                if (uid == 0) {
                    mainVue.searchForm = $("#searchForm").serialize() + '&is_agent=' + is_agent + '&project_id=' + project_id;
                    console.log(mainVue.searchForm)
                } else {
                    mainVue.searchForm = $("#searchForm").serialize() + '&user_id=' + uid + '&is_agent=' + is_agent;
                }
            } else {
                if (uid == 0) {
                    mainVue.searchForm = $("#searchForm").serialize() + '&project_id=' + project_id;
                } else {
                    mainVue.searchForm = $("#searchForm").serialize() + '&user_id=' + uid;
                }
            }
            $.get(
                "{% url 'task:filter_tasks_admin' %}",
                mainVue.searchForm,
                function (response) {
                    if (response) {
                        mainVue.limit = response.limit;
                        mainVue.showMain = true;
                        mainVue.limits = response.limits;
                        mainVue.tableData = response.tableData;
                        mainVue.paginator = response.paginator;
                        mainVue.message = response.message;
                        mainVue.total = response.total;
                        mainVue.incomes = response.incomes;
                        {#console.log(mainVue.tableData)#}
                    } else {
                        mainVue.showMain = false;
                    }
                }
            )
        }

        function TasksDownload() {

            var uid = {{ uid|safe }};
            if (is_agent === '1') {
                if (uid == 0) {
                    mainVue.searchForm = $("#searchForm").serialize() + '&is_agent=' + is_agent + '&project_id=' + project_id;

                } else {
                    mainVue.searchForm = $("#searchForm").serialize() + '&user_id=' + uid + '&is_agent=' + is_agent;
                }
            } else {
                if (uid == 0) {
                    mainVue.searchForm = $("#searchForm").serialize() + '&project_id=' + project_id;
                } else {
                    mainVue.searchForm = $("#searchForm").serialize() + '&user_id=' + uid;
                }
            }
            console.log(mainVue.searchForm)
            window.open("http://wego.istarshine.com/task/task_download/?" + mainVue.searchForm)
        }

        searchTasks();

        //$("#taskManager").addClass("active");
        function changeColor(id, color) {
            //$(id).parent().parent().parent().children().children().children().find("li[color='green']");
            $(id).parent().parent().addClass("active");
            $(id).children().css("color", color);
        }

        //$("#taskManager").addClass("active");
        // 获取url参数值
        function GetQueryValue(queryName) {
            var query = decodeURI(window.location.search.substring(1));
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == queryName) {
                    return pair[1];
                }
            }
            return null;
        }

        // var a_url = href = window.location.href;
        if ('{{ is_agent }}' === '1') {
            if (GetQueryValue('status') == 1) {
                changeColor("#allocate_task_agent", "#00FF7F");
            } else {
                changeColor("#manage_agent", "#00FF7F");
            }
        } else {
            if (GetQueryValue('status') == 1) {
                changeColor("#allocate_task", "#00FF7F");
            } else {
                changeColor("#manage", "#00FF7F");
            }
        }

        {# 重新分派 #}

        function Assignment(tids, agency_id) {
            _Assignment(tids, agency_id)
        }

        function _Assignment(tids, agency_id) {
            if (!tids) {
                var _tids = [];
                var _agency_id = [];
                $("input[name='td_checkbox']:checked").each(
                    function () {
                        _tids.push($(this).val())
                        _agency_id.push($(this).attr('id'))
                    }
                );
                let s = _agency_id[0];
                for (let i = 1; i < _agency_id.length; i++) {
                    if (s != _agency_id[i]) {
                        alert('已选任务不属于同一项目，无法分配!');
                        return false
                    }
                }
                agency_id = s;
                tids = _tids.join();
            }
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false
            } else {
                $("#taskIds").val(tids);
                showUsers_Assignment(tids, agency_id);
            }
        }

        function showUsers_Assignment(tids, agency_id) {
            var bbb = $("#bbb");
            bbb.html('');
            {% for user in configUsers %}
                if ({{ user.user.agency_id }} == agency_id ){
                bbb.append("<tr>\n" +
                    "                                    <td class=\"action-checkbox\">\n" +
                    "                                        <input type=\"radio\" name=\"utd_checkbox\" value=\"{{ user.user.id }}\" onclick=\"_checkOne(this)\">\n" +
                    "                                    </td>\n" +
                    "                                    <td>{{ user.user.username }}</td>\n" +
                    "                                    <td>{{ user.user.real_name }}</td>\n" +
                    "                                </tr>");
            }

            {% endfor %}
            if (bbb.html() === '') {
                alert('未获到该组所属用户！')
            } else {
                var userBox = $("#userListAssignment");
                userBox.modal();
            }

        }

        function confirmCloseAssignment() {
            var tids = $("#taskIds").val();
            var userIds = [];
            $("input[name='utd_checkbox']:checked").each(
                function () {
                    userIds.push($(this).val());
                }
            );
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false;
            }
            uids = userIds.join();
            if (uids.length === 0) {
                $("#userMessage").modal();
                return false
            }
            allocateAssignment(tids, uids);
            $("#bbb").html('');
            _clearChecked();
        }

        function cancelCloseAssignment() {
            $("#bbb").html('');
            _clearChecked();
        }

        function allocateAssignment(tids, uids) {
            if (!tids) {
                tids = $("#taskIds").val();
            }
            if (!uids) {
                var _uids = [];
                $("input[name='utd_checkbox']:checked").each(
                    function () {
                        _uids.push($(this).val())
                    }
                );
                uids = _uids.join();
            }
            if (uids.length === 0) {
                return false
            }
            if (tids.length === 0) {
                console.log(tids, uids);
                $("#taskMessage").modal();
                return false
            } else {
                $.ajaxSetup({
                    data: {
                        csrfmiddlewaretoken: '{{ csrf_token }}',
                        tids: tids,
                        uids: uids
                    }
                });
                $.post(
                    "{% url 'task:allocate' %}",
                    function (response) {
                        var msg = response.message;
                        console.log(msg);
                        if (msg) {
                            alert(msg);
                        }
                        mainVue.message = response.message;
                        toPage('current');
                        clearCheckAll();
                    }
                )
            }
            $("#taskIds").val("");
        }

        {#回收#}

        function recoveryOne(tids) {
            if (tids) {
                tids = tids + "";
                $("#taskIds").val(tids);
                $("#recoveryMessage").modal();
            } else {
                return false
            }
        }

        function recovery(tids) {
            if (!tids) {
                tids = $("#taskIds").val();
            }
            if (tids.length === 0) {
                alert('获取任务失败！')
                return false
            } else {
                __recovery(tids)
            }
            $("#taskIds").val("")
        }

        function __recovery(tids) {
            $.ajaxSetup({
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    tids: tids
                }
            });
            $.post(
                "{% url 'task:RecoveryApplication' %}",
                function (response) {
                    var msg = response.message;
                    if (msg) {
                        alert(msg);
                    }
                    toPage("current");
                    clearCheckAll();
                }
            )
        }

        {#驳回#}

        function disposalOne(tids) {
            if (tids) {
                tids = tids + "";
                $("#taskIds").val(tids);
                $("#disposalMessage").modal();
            } else {
                return false
            }
        }

        function disposal(tids) {
            if (!tids) {
                tids = $("#taskIds").val();
            }
            if (tids.length === 0) {
                $("#taskMessage").modal();
                return false
            } else {
                __disposal(tids)
            }
            $("#taskIds").val("")
        }

        function __disposal(tids) {
            $.ajaxSetup({
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    tids: tids
                }
            });
            $.post(
                "{% url 'task:DisposalApplication' %}",
                function (response) {
                    var msg = response.message;
                    if (msg) {
                        alert(msg);
                    }
                    toPage("current");
                    clearCheckAll();
                }
            )
        }

        //when page onload, init the table.
        //render(mainVue);
        laydate.render({
            elem: '#test1'
            , range: true
        });
        laydate.render({
            elem: '#test2'
            , range: true
        });
        laydate.render({
            elem: '#test3'
            , range: true
        });
        laydate.render({
            elem: '#test4'
            , range: true
        });
        laydate.render({
            elem: '#test5'
            , range: true
        });

    </script>
    <script>
        // 提交质检确认
        function submit_inspection() {
            var _tids = [];
            var _status_ids = [];
            var _is_submit_qualitys = [];
            $("input[name='td_checkbox']:checked").each(
                function () {
                    _status_ids.push($(this).attr('status_id'));
                    _is_submit_qualitys.push($(this).attr('is_submit_quality'));
                    _tids.push($(this).val());
                }
            );
            // 判断是否选中任务
            if (_tids.length === 0) {
                alert("您没有选中任务");
                return false;
            }
            for (let i = 0; i < _status_ids.length; i++) {
                if (_status_ids[i] != "已合格") {
                    alert("选择任务中包含不是已合格的任务");
                    return false
                }
            }
            //for (let i = 0; i < _is_submit_qualitys.length; i++) {
            //    if (_is_submit_qualitys[i] != "否") {
            //        alert("选择任务中包含已提交质检的任务");
            //        return false
            //    }
            //}
            $("#sv_count").val(_tids.length);
            $("#sv_ids").val(_tids.join());
            $("#submit_inspection_verify").modal();
        }

        function _submit_inspection() {
            var tids = $("#sv_ids").val().split(',');
            $.ajax({
                url: "/quality/SupplierQuality/SupplierAdminCreateQualityPackage/",
                type: "POST",
                contentType: 'application/json',
                dateType: "json",
                data: JSON.stringify({"id_list": tids}),
                success: function (data) {
                    alert(data.data);
                    {#location.reload();#}
                },
                error: function (data) {
                    alert(JSON.parse(JSON.stringify(data)));
                }
            })
        }

        // 复制
        function copy_text(text) {
            $("#copy_text_input").val(text);
            $("#copy_text_input").select();
            document.execCommand('Copy');
            alert('复制成功')
        }
    </script>
{% endblock section_content %}
